package com.topisv.tms.utils.rule;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.topisv.tms.repository.CustomersDao;

@Component
public class TMSRule {
	@Autowired
	private CustomersDao customersDao;
	
	private static final Logger log = LoggerFactory.getLogger(TMSRule.class);

	/**
	 * 根据商家编码获得运单号
	 * 
	 * @param code
	 * @return
	 * @throws Exception
	 */
	@Transactional(rollbackFor=Exception.class,readOnly = false)
	public String getNumber(String code) throws Exception {
		try {
			log.info("开始申请运单号:"+code);
			//Customers customers = customersDao.findByCustomerCode(code);// 根据客户编码获得客户信息
			//log.info("起始运单号:"+customers.getEndNumber());
			//String temp = TMSTransportRule.getExpress(customers);// 得到运单号
			//log.info("申请到的运单号:"+customers.getEndNumber());
			//customersDao.save(customers);
			return TMSTransportRule.generateWaybillNo();

		} catch (Exception e) {
			log.error("getNumber error", e);
			throw e;
		}
	}
	
	@Transactional(rollbackFor=Exception.class,readOnly = false)
	public String getStartOrdeno(String code) throws Exception {
		try {
			log.info("开始申请订单号:"+code);
			/*Customers customers = customersDao.findByCustomerCode(code);// 根据客户编码获得客户信息
			log.info("起始订单号:"+customers.getStartOrdeno());
			String temp = TMSTransportRule.getStartOrdeno(customers);//得到新的订单号
			log.info("申请到的订单号:"+customers.getStartOrdeno());
			customersDao.save(customers);*/
			return TMSTransportRule.generateOrderNo();

		} catch (Exception e) {
			log.error("getStartOrdeno error", e);
			throw e;
		}
	}
}
